﻿@page "/api"

@inject HttpClient Client

<button @onclick="GetDataAsync">获取远程数据</button>

@if(Data is null)
{
    <div>数据加载中...</div>
}
else
{
    <GenaricTable Data="Data">
        <HeaderTemplate>
            <th>日期</th>
            <th>摄氏度</th>
            <th>华氏度</th>
            <th>说明</th>
        </HeaderTemplate>
        <RowTemplate>
            <td>@context.Date</td>
            <td>@context.TemperatureC</td>
            <td>@context.TemperatureF</td>
            <td>@context.Summary</td>
        </RowTemplate>
    </GenaricTable>
}


@code {
    IEnumerable<WeatherForecast>? Data { get; set; }

    async Task GetDataAsync()
    {
        Data = await Client.GetFromJsonAsync<IEnumerable<WeatherForecast>>("WeatherForecast");

    }

    public class WeatherForecast
    {
        public DateOnly Date { get; set; }

        public int TemperatureC { get; set; }

        public int TemperatureF { get; set; }

        public string? Summary { get; set; }
    }
}
